///**
// * 
// */
package org.youisoft.summer.evaluator.impl;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.youisoft.summer.evaluator.context.CalContext;
import org.youisoft.summer.evaluator.eval.AbstractExpressionEvaluator;
import org.youisoft.summer.evaluator.function.Function;


/**
 * 
 * @author zijiang.jl
 * 
 *
 */
public class MapResourceEvaluator extends AbstractExpressionEvaluator<Object,Map<String,Object>,Properties>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	

	/**
	 * @author zijiang.jl
	 *
	 */
	public static class Utility{
		
		public static Object evaluate(CalContext<Object,Map<String,Object>,Properties> context,String conditions,List<Function> funs){
			if(conditions==null||"".equals(conditions)) return true;
			try {
				return getEvaluator(context,funs).prepare(conditions).evaluate(context);
			} catch (Exception e) {
				throw new java.lang.RuntimeException(e.getMessage());
			}
		}
		
		private static MapResourceEvaluator getEvaluator(CalContext<Object,Map<String,Object>,Properties> context,List<Function> funs){
			MapResourceEvaluator evaluator=new MapResourceEvaluator();
			evaluator.setParenthesisClassName(MapResouceParenthesis.class.getName());
			evaluator.setBraceClassName(MapResourceBrace.class.getName());
			evaluator.setBracketClassName(MapResourceBracket.class.getName());
			if(funs!=null)
			for(Function fun:funs){
				evaluator.register(fun);
			}
			evaluator.init();
			return evaluator;
		}
		
		public static Object evaluate(CalContext<Object,Map<String,Object>,Properties> context,String conditions){
			if(conditions==null||"".equals(conditions)) return true;
			try {
				return getEvaluator(context,null).prepare(conditions).evaluate(context);
			} catch (Exception e) {
				throw new java.lang.RuntimeException(e.getMessage());
			}
		}
	}
}



